<?php

/**
 * reservation
 *
 * @version $Rev:$
 * @license 
 */
class Tour_Model_Reservation extends Zend_Db_Table_Abstract
{

    public function __construct($config = array())
    {
        $this->_db = Zend_Db_Table::getDefaultAdapter();
        parent::__construct($config);
    }
    
    public function countReservationList($idCompany){
        $selectCount = $this->_db->select()
                                 ->from(array('tr'=>'tour_reservation'),
                                     array('COUNT' =>'count(*)'))
                                 ->where('tr.id_company = ? ',$idCompany);
        $count = $this->_db->fetchAll($selectCount);
        return $count[0]['COUNT'];
    }
    
    public function selectReservationList($idCompany,$page,$search)
    {
        $offset = $page * 10;
        $select = $this->_db->select()
                            ->from(array('tr'=>'tour_reservation'),
                                     array('TITLE'=>'title','TENKHACHHANG'=>'full_name','DIENTHOAI'=>'phone','THOIGIANDANGKY'=>'reservation_date'))
                            ->join(array('tct' => 'tourist_company_tour'),
                                         'tr.id_company = tct.id',
                                         array('MA_TOUR'=>'code')
                                        )
                            ->where('tr.id_company = ? ',$idCompany);
        
        if($search['FROMDATE'] != ""){
            $select->where('tr.reservation_date >= ? ',$search['FROMDATE']);
        }
        if($search['TODATE'] != ""){
            $select->where('tr.reservation_date <= ? ',$search['TODATE']);
        }
        
        $select->order(array('tct.code DESC'))
               ->limit(10,$offset);
        $data = $this->_db->fetchAll($select);
        return $data;
    }

}

